
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[EBAS_SP_SLET_GRUPPE]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[EBAS_SP_SLET_GRUPPE]
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE [DBO].[EBAS_SP_SLET_GRUPPE] 
	@session varchar(255),
	@guid varchar(255)
WITH ENCRYPTION
AS
	DECLARE @rettighed int,
		@antal int
	
	SET NOCOUNT ON
	SET @antal = 0

	CREATE TABLE #temp ( rett int )
	INSERT INTO #temp (rett)
	EXEC EBAS.DBO.EBAS_SP_SIKKERHED_VERIFICER_SESSION @session	

	SET @rettighed = (SELECT IsNull(MAX(rett),0) FROM #temp)
	
	IF 8 <= @rettighed 
	BEGIN
		SET @antal = 1
		
		DELETE FROM EBAS_GRUPPE_STUDERENDE
		WHERE GRUPPE_GUID = @guid
		
		DELETE FROM EBAS_GRUPPE
		WHERE GUID = @guid
		
		SELECT @antal AS ANTAL	
	END
	ELSE	
		SELECT @antal AS ANTAL
		FROM EBAS_GRUPPE
		WHERE GUID IS NULL
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
